<html>
<head><title>Labyture = LABYrinth + ligaTURE</title>
<style>
body {
	padding: 0px 0px 0px 0px;
	margin: 0px 0px 0px 0px;
}
button.collection {
	border: thin grey outset;
	margin: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
}
pre {
	padding: 0px 0px 0px 0px;
	margin: 0px 0px 0px 0px;
}
select {
	font-family: Courier;
	font-size: 10px;
}
table.Display {
	font-family: Courier;
	font-size: 1px;
}
table.Display td {
	border: 0px 0px 0px 0px;
	padding: 0px 0px 0px 0px;
	margin: 0px 0px 0px 0px;
	width: 8px;
	height: 8px;
}
table.Display td.x0 {
	background-color: black;
	color:	white;
}
table.Display td.x1 {
	background-color: #FFE0E0;
	color:	black;
}
table.Display td.x2 {
	background-color: #E0E0FF;
	color:	black;
}
table.Display td.x3 {
	background-color: white;
	color:	black;
}
table.Display td.x4 {
	background-color: #FFFFE0;
	color:	black;
}
table.Display td.x5 {
	background-color: #606060;
	color:	black;
}
table.Display td.x6 {
	background-color: #808080;
	color:	black;
}
table.Display td.x7 {
	background-color: #CCCCCC;
	color:	black;
}
.x0 {
	background-color: black;
	color:	white;
}
.x1 {
	background-color: black;
	color:	#FFE0E0;
}
.x2 {
	background-color: black;
	color:	#E0E0FF;
}
.x3 {
	background-color: black;
	color:	#FFE0FF;
}
pre#Log {
	font-family: 'Courier New';
	font-size: 11px;
}
pre#Pseudo {
	background-color: black;
	color: white;
	font-family: 'Courier New';
	font-size: 8px;
}
table#Vectors td {
	border: 0 0 0 0;
	margin: 0 0 0 0;
	padding: 0 0 0 0;
	font-family:Courier New;
	font-size: 12px;
	font-height: 16px;
}
table#Designs td {
	border: 0 0 0 0;
	margin: 0 0 0 0;
	padding: 0 0 0 0;
	font-family:Courier New;
	font-size: 14px;
	font-height: 14px;
}
</style>
<script>
/*****************************************************************************
Alikberov Ruslan (C) 2014.12.16
*****************************************************************************/
var
	Collections = {
		Alikberov	:"0000 47F8 4208 43C8 3AA8 68B8 1F80 32E0 0F40 0400 07A0 0AE0 0EA0 0000",//"0000 4030 4050 3A70 6BD0 0950 3F10 6550 1E70 0800 0F40 15C0 1D40 0000",
		Alikberov2	:"0000 0030 0010 3A50 6BD0 0970 1F50 3510 0450 0F70 0200 03D0 0970 0F50 0000", // 11x13:24 143-24=119
		Alikberov3	:"0000 3A5E 6BC2 097E 1F42 350A 042E 0F60 0220 03F0 0110 0140 01C0 0000", // 14x12:41 168-41=127 //"00000 1FF98 108C8 15E08 3C428 657E8 054A8 55688 5F2A8 418E8 41008 7FFF8 00000",//"0000 3FF0 2114 2BD0 7884 4AFC 2A94 3ED0 4310 5AD0 4254 7FDC 0000",										//"0000 3FEE 2122 2BCA 78A2 4AE2 2ABA 3EAA 42DA 7322 6A02 6FFE 0000",
		AlikberovA	:"000 1CC 356 05A 3F6 69C 1E6 044 07A 0AE 0EA 000",
		AlikberovB	:"0000 3960 6B30 0950 3F70 65D0 1E40 0800 0F40 15C0 1D40 0000",
		Akvarium	:"0000 0006 000A 00FA 7DAE 082A 6EA2 2AAA 68EA 3FAA 00BA 4002 7FFE 0000",//"0000 77EC 0214 7DF4 115C 5C54 5544 51D4 7F54 2174 5404 77FC 0000",										//"0000 77B0 3E50 41D0 7D70 4150 5910 49D0 7D50 5250 43D0 7E50 02D0 4010 7FF0 0000",
		Gotika		:"000 7C2 05E 7D4 456 554 550 554 5D6 412 57E 702 5FE 500 000",//"0000 3FFC 0004 5FFC 5044 0274 5ED4 7254 5214 17F4 4004 7FFC 0000",										//"0000 37FC 7004 25FC 5D04 7514 55F4 2554 5454 5FD4 4004 7FFC 0000",
		Displey		:"00000 7FFE4 000A8 7FFA4 400A8 5FE24 522A8 568A0 53EEC 52084 7BEFC 00000",									//"000000 3FFFF0 500010 53FFD0 520050 572A50 54AF50 579850 50AFD0 5FE050 400010 7FFFF0 000000",
		Enciklopedia:"00000 7FFF8 40000 5F7F0 52450 7A550 43F40 5A178 4B448 786E8 0A408 09FF8 4A800 7F558 40008 7FFF8 00000",	//"00000 7FFF0 00810 54FD0 7E850 01DD0 7E150 52910 179D0 78890 22B90 2BE90 2C250 2A950 3FB70 00000",
		Internet	:"0000 2FF6 2012 7FF2 1012 5FD2 5052 5B52 4552 5752 5452 4FD2 5052 5F92 50F2 568A 5002 7FFE 0000",			//"00000 3FFFC 50004 5F414 553E4 54924 557A4 57224 522A4 57BA4 51024 4DFF4 40004 7FFFC 00000",
		Konstitucia	:"00000 5EFF8 56820 5CB60 40938 7FF28 00008 7FFF8 40008 7FFE8 42028 6BFA8 0A0A8 5DFA8 708A8 5FBA8 40868 00000",//"0000 7FFE 0002 5FFE 5002 5FFA 500A 55FA 1D0A 55F2 4822 5DEA 70BA 5F82 20F2 3FAA 002E 0000",
		Konstitucia2:"0000 7FFE 0002 7FFE 5002 1FFA 700A 15FA 550A 55F2 4A22 5DEA 70BA 5F82 20F2 3FAA 402E 0000",
		Konstitucia3:"0000 7FFE 0002 77FE 6402 07FA 040A 057A 074A 0572 0822 5DEA 70BA 5F82 20F2 3FAA 002E 0000",
		Konstitucia4:"0000 7FFE 0002 6FFE 6A02 43FA 1E0A 02FA 428A 78F2 5642 4D7A 55D2 5C12 57F2 4012 7FF2 000A 000E 0000",
		Konstitucia5:"0000 3FFF8 40008 5BFF8 5A808 50FE8 41828 40BE8 50228 5E3C8 55908 535E8 55748 57048 55FC8 50048 5FFC8 40008 7FFF8 00000",
		Konstitucia6:"00000 3FFFC 40004 5D034 51FD4 5F054 517D4 51444 51744 51284 502F4 51BA4 53024 557E4 57224 55EA4 502E4 50004 7FFFC 00000",
		Monitor		:"0000 7FF8 0008 7DE8 24A8 2FA8 20A8 3E28 2A28 1AA8 4AA8 7A28 0AA8 76F8 0000",								//"0000 420C 7BF4 4E14 4AF4 4554 5B54 5554 4754 5154 5FD4 4004 7FFC 0000",
		Monitor2	:"0000 41DE 7A02 4BFA 4A0A 4EFA 4A2A 40AA 5FAA 44AA 56AA 50AA 5FEA 4002 7FFE 0000",
		Panda		:"0000 400C 5FF4 5414 56D4 5414 5704 55F4 5514 5554 5574 5554 5534 5004 7FFC 0000",
		Reversi		:"0000 7FF8 0108 75E8 1488 75E8 5C48 4548 6F48 41C8 7408 07F8 0000",
		Manuskript	:"00000 40006 7FFFA 4200A 4BFAA 5A0AA 5308A 4278A 4028A 5FE0A 5020A 57DE2 5493A 5EFAA 4080A 40FBA 40002 7FFFE 00000",
		Manuskript2	:"000000 40000C 7FFFF4 420014 4BFBD4 5A0004 43FFF4 5A0014 503DD4 57A454 552454 55F7D4 550414 55F5F4 540054 5FFFD4 400054 400004 7FFFFC 000000",
		Manuskript3	:"0000000 3FFFFF0 4000000 5FFEFF0 5000200 57DE370 5513A00 55FABF0 5500A10 55BBAF0 5400050 5FFFFD0 4000040 4000000 7FFFFF0",//"0000000 3FFFFFF 4000001 5FFEFFD 5000205 57DFBF5 5512A05 55FA3F5 5502A15 55FBAF5 5400055 5FFFFD5 4000045 4000005 7FFFFFF 0000000",
		Domik		:"0000 7CF0 1410 74D0 5450 0550 2F50 4150 7FD0 4010 7FF0 0000",
		Domik2		:"0000 3FFC 4004 5F14 4504 5D74 5514 4154 5FD4 4054 7FF4 4004 7FFC 0000",
		Kapusta		:"0000 3FFC 4004 5EF4 5494 57D4 1414 53F4 5114 5744 5574 5444 57F4 5414 56F4 5004 7FFC 0000",
		Klubnika	:"00000 3FFFC 40004 1EF04 549F4 57D54 55044 555C4 54754 57554 50004 7FFFC 00000",
		Ruslan		:"00000 5FED0 50558 575E0 52518 5E7E8 22008 3FFF8 40008 7FFF8 00000",
		Test		:"00000 7FFFC 00014 74954 29174 2CBA4 28524 2D8A4 40024 53FE4 4A124 4A524 53774 40004 7FFFC 00000"
	};
function	Collector() {
	var
		Last = "", html = "";
	for(var i in Collections) {
		if(Last && Last == i.substr(0, Last.length)) {
			html += "<button class='Collection' onclick='Print(Collections." + i + ")'>" + i.substr(Last.length) + "</button>";
		} else
			html += (Last ? " " : "") + "<button class='Collection' onclick='Print(Collections." + i + ")'>" + i + "</button>",
			Last = i;
	}
	return html;
}
function Scan(obj, n, r, f) {
var
 res = '';
 if(n > 2)
  return r.substr(0, r.length - 1) + " = [...]\n";
 try {
  for(i in obj) {
  //alert(typeof(obj[i]));
   if(f == "") {
    if(typeof(obj[i]) == "object")
     res += Scan(obj[i], n + 1, r + i + '.', f);
    else
     res += r + i + ' = ' + obj[i] + '\n';
   } else {
    if(typeof(obj[i]) == "object")
	 res += Scan(obj[i], n + 1, r + i + '.', f);
	else
	 res += f == obj[i] ? r + i + ' = ' + obj[i] + '\n' : "";
   }
  }
 }
 catch(e) {
  window.status = r + i + ' -> ERROR AT ' + n + ' :: ' + e;
  return res + 'err\n';
 }
 return res;
}
var
	Matrix = [],
	Stack = [],
	Paint = [],
	Book = [],
	MouseDraw = {x1: -1, y1: -1, x2: -1, y2: -1, pen: 0};
var
	Draw_oem = true,
	Speed = 125, Bug_anim = 0,
	Bug_px = 0, Bug_py = 0, Bug_l = 0, Bug_r = 0, Bug_x = 2, Bug_y = 1, Bug_z = 1, Bug_vovel = 0, Bug_w = 0, Bug_s = true, Bug_fine = 0,
	Bug_xl = 0, Bug_yl = 0, Bug_fx = 0, Bug_sm = 0;
var
	MinX = 1, MinY = 1, MaxX = 0, MaxY = 0;
	
function DrawASCII(Decode) {
	var	Sign = "", html = "", sym = [0xB7, 0x2580, 0x2584, 0x2588];
	var	smb = [0xB7, 0x2598, 0x259D, 0x2580, 0x2596, 0x258C, 0x259E, 0x259B, 0x2597, 0x259A, 0x2590, 0x259C, 0x2584, 0x2599, 0x259F, 0x2588];
	var	dsp = document.getElementById("Display");
	var	log = document.getElementById("Log");
	var	Vec = document.getElementById("Vectors");
	var	WordList = document.getElementById("Words");
	var	Designs = document.getElementById("Designs");
	var	Logs = [], Books = [], Dirs = [], Word = [""];
	var	Anim = 0, Ani = Bug_anim ^ (Decode && Bug_vovel ? 0 : (Bug_anim >> 1));
	var	Caps = {
		11036: ["·", "012302",
			  "01230", "12301", "23012", "30123",
			  "32103", "21032", "10321", "03210",
			  "0123", "1230", "2301", "3012",
			  "3210", "2103", "1032", "0321"],
		0x2293: ["PB", "0121 ", "0323 ", "1012 ", "3032 ", "012", "032"],
		0x2290: ["DT", "1232 ", "1030 ", "2123 ", "0103 ", "123", "103"],
		0x2294: ["VF", "2303 ", "2101 ", "3230 ", "1210 ", "230", "210"],
		0x228F: ["CS", "3010 ", "3212 ", "0301 ", "2321 ", "301", "321"],
		0x251C: ["A", "746", "764", "45", "65", "05", "25"],
		0x252C: ["U", "457", "475", "56", "76", "16", "36"],
		0x2524: ["O", "564", "546", "67", "47", "27", "17"],
		0x2534: ["E", "675", "657", "74", "54", "34", "04"],
		0x250C: ["GK", "010 ", "323 ", "01", "32"],
		0x2510: ["MN", "121 ", "030 ", "12", "03"],
		0x2518: ["JH", "232 ", "101 ", "23", "10"],
		0x2514: ["LR", "303 ", "212 ", "30", "21"],
		0x2502: ["I", "4", "5", "6", "7"]
	};
	if(Bug_xl != Bug_x || Bug_yl != Bug_y) {
		if(Draw_oem)
			for(var y = 0; y < 32; ++ y)
				for(var x = 0; x < 64; ++ x) {
					var b1 = dsp.rows[y * 2 + 0].cells[x].className;
					var b2 = dsp.rows[y * 2 + 1].cells[x].className;
					var g1 = "x1x2x3x4x7".indexOf(b1) >= 0 ? 1 : 0;
					var g2 = "x1x2x3x4x7".indexOf(b2) >= 0 ? 2 : 0;
					var	color = 0;
					if(b1 == "x1" || b2 == "x1" || b3 == "x1" || b4 == "x1")
						color |= 1;
					if(b1 == "x2" || b2 == "x2" || b3 == "x2" || b4 == "x2")
						color |= 2;
					html += (y && !x ? "<br />" : "") + "<span class=x" + color + ">&#" + sym[g1 + g2] + ";</span>";
				}
		else
			for(var y = 0; y < 32; ++ y)
				for(var x = 0; x < 32; ++ x) {
					var b1 = dsp.rows[y * 2 + 0].cells[x * 2 + 0].className;
					var b2 = dsp.rows[y * 2 + 0].cells[x * 2 + 1].className;
					var b3 = dsp.rows[y * 2 + 1].cells[x * 2 + 0].className;
					var b4 = dsp.rows[y * 2 + 1].cells[x * 2 + 1].className;
					var g1 = "x1x2x3x4x7".indexOf(b1) >= 0 ? 1 : 0;
					var g2 = "x1x2x3x4x7".indexOf(b2) >= 0 ? 2 : 0;
					var g4 = "x1x2x3x4x7".indexOf(b3) >= 0 ? 4 : 0;
					var g8 = "x1x2x3x4x7".indexOf(b4) >= 0 ? 8 : 0;
					var	color = 0;
					if(b1 == "x1" || b2 == "x1" || b3 == "x1" || b4 == "x1")
						color |= 1;
					if(b1 == "x2" || b2 == "x2" || b3 == "x2" || b4 == "x2")
						color |= 2;
					html += (y && !x ? "<br />" : "") + "<span class=x" + color + ">&#" + smb[g1 + g2 + g4 + g8] + ";</span>";
				}
		document.getElementById("Pseudo").innerHTML = html;
		Bug_xl = Bug_x, Bug_yl = Bug_y;
	}
	for(var i in Book)
		Books.push("NESWnesw_".charAt(Book[i])),
		Dirs.push("&#" + [0x21E7, 0x21E8, 0x21E9, 0x21E6, 0x21E1, 0x21E2, 0x21E3, 0x21E0, 0x20, 0x21BA][Book[i]]);
	for(var i = 0, s, ii; i < Book.length; i += ii) {
		s = "" + Book[i] + Book[i + 1] + Book[i + 2] + Book[i + 3];
		ii = 1;
		while(s.length) {
			for(var j in Caps) {
				for(var k in Caps[j]) {
					if(Caps[j][k].replace(" ", "") == s) {
						if(Caps[j][k].indexOf(" ") >= 0)
							Bug_fine |= 1 << Anim;
						ii = s.length; s = "";
						var	jj = Caps[j][0];
						Vec.rows[0].cells[Sign.split(' ').length - 1].innerHTML = "<b style=color:" + (jj.length > 1 ? "blue>" : "red>") + jj[jj.length > 1 ? (Ani >> Anim) & 1 : 0] + "</b>";
						Vec.rows[1].cells[Sign.split(' ').length - 1].innerHTML = "<b style=color:" + (jj.length > 1 ? "blue>&#" : "red>&#") + j + ";</b>";
						Sign += "<span style=color:" + (jj.length > 1 ? "blue>&#" : "red>&#") + j + ";</span>";
						if(jj.length > 1)
							Anim ++;
						break;
					}
				}
			}
			s = s.substr(0, s.length - 1);
		}
	}
	if(Decode && (WordList.length == Ani)) {
		var option = document.createElement("option");
		option.value = option.text = Ani + ":" + Vec.rows[0].innerText;
		WordList.add(option);
	} else
	if(Decode && (WordList.length == (1 << Anim))) {
		Bug_vovel = 0;
		if(!WordList.selectedIndex) {
			var i = Fine();
			if(i >= 0) {
				WordList.selectedIndex = i & (WordList.length - 1),
				document.getElementById("Message").innerText += WordList.options[WordList.selectedIndex].value + " ";
				var	x = Bug_x, y = Bug_y;
				if(FindBox() || FindBox_neo()) {
					Bug_x = x, Bug_y = y;
					setTimeout("Print(' ')", 1500);
				}
			}
		}
	}
	Bug_anim = (Bug_anim + 1) & ((1 << Anim) - 1);
	for(Anim = Sign.split(' ').length; Anim < Vec.rows[2].cells.length; ++ Anim)
		Vec.rows[0].cells[Anim].innerText = " ", Vec.rows[1].cells[Anim].innerText = " ";
	Logs.push("Key: " + Ani + "/" + Bug_fine.toString(2) + " Angle:" + Bug_w + " FX:" + Bug_sm + "/" + Bug_fx + "=" + Math.floor(Bug_sm ? 1000 * (Bug_sm - Bug_fx) / Bug_sm : 0) / 10 + "%");
	Logs.push("User:" + MouseDraw.x1 + "," + MouseDraw.y1 + "-" + MouseDraw.x2 + "," + MouseDraw.y2);
	Logs.push("Fill:" + Bug_z + "#" + Bug_x + "," + Bug_y + " <i style=color:" + (Bug_s ? "gray>container" : Bug_vovel ? "red>vovel" : "blue>consonant") + "</i>");
	Logs.push("Stack:");
	for(var i in Stack)
		Logs.push(Stack[i].x + "," + Stack[i].y + ":" + Stack[i].z);
	log.innerHTML = Logs.join("<br>");
	for(var i = 0; i < Designs.rows[0].cells.length; ++ i)
		Designs.rows[0].cells[i].innerHTML = i < Dirs.length ? Dirs[i] : "&nbsp;",
		Designs.rows[1].cells[i].innerHTML = i < Books.length ? Books[i] : "&nbsp;",
		Designs.rows[2].cells[i].innerHTML = i < Book.length ? Book[i] : "&nbsp;";
}
function main() {
var
	Display = document.createElement("table"),
	x, y,
	row, cell;
	document.getElementsByTagName("div")[0].innerHTML = Collector();
	Display.id = "Display";
	Display.className = "Display";
	Display.cellSpacing = "0px";
	Display.addEventListener("selectstart", function (evt) {
		return false;
	});
	Display.addEventListener("mousedown", function (evt) {
		evt = evt || window.event;
		var elm = evt.target ? evt.target : evt.srcElement;
		var par = elm.parentNode;		//document.getElementsByTagName("span")[0].innerText = elm.cells + "<br>" + Scan(elm, 0, "", "");//		elm.offsetParent.cells[elm.cellIndex + par.rowIndex * 64].style.backgroundColor = "blue";
		MouseDraw = {
			x1: elm.cellIndex,
			y1: par.rowIndex,
			x2: elm.cellIndex,
			y2: par.rowIndex
		};
		var	idx = MouseDraw.x2 + MouseDraw.y2 * 64;
		elm.offsetParent.cells[idx].className = (MouseDraw.pen = elm.offsetParent.cells[idx].className == "x3" ? "x0" : "x3");
		evt.returnValue = 0;
		if(Speed < 0)
			Bug_x = elm.cellIndex, Bug_y = par.rowIndex;
		return false;
	});
	Display.addEventListener("mouseup", function (evt) {
		evt = evt || window.event;
		var elm = evt.target ? evt.target : evt.srcElement;
		var	dsp = document.getElementById("Display");
		var	z = [], max = 0, flag = true;
		if(Speed < 0) {
			if(MouseDraw.x1 == MouseDraw.x2 && MouseDraw.y2 < MouseDraw.y1)
				Bug_z = 0; else
			if(MouseDraw.x1 == MouseDraw.x2 && MouseDraw.y2 > MouseDraw.y1)
				Bug_z = 2; else
			if(MouseDraw.x1 < MouseDraw.x2 && MouseDraw.y2 == MouseDraw.y1)
				Bug_z = 1; else
			if(MouseDraw.x1 > MouseDraw.x2 && MouseDraw.y2 == MouseDraw.y1)
				Bug_z = 3;
		}
		for(var x = 0; x < 28; ++ x) {
			if(dsp.rows[0].cells[x].className != "x0") {
				for(var y = 0; y <= 28; ++ y)
					for(var x = 0; x < 28; ++ x)
						dsp.rows[28 - y].cells[x].className = y < 28 ? dsp.rows[27 - y].cells[x].className : "x0";
				break;
			}
		}
		for(var x = 0; x < 28; ++ x)
			flag = dsp.rows[1].cells[x].className == "x0" ? flag : false;
		if(flag) {
			for(var y = 0; y < 28; ++ y)
				for(var x = 0; x < 28; ++ x)
					dsp.rows[y].cells[x].className = dsp.rows[1 + y].cells[x].className;
		}
		for(var y = 0; y < 28; ++ y) {
			if(dsp.rows[y].cells[0].className != "x0") {
				for(var x = 0; x <= 28; ++ x)
					for(var y = 0; y < 28; ++ y)
						dsp.rows[y].cells[28 - x].className = x < 28 ? dsp.rows[y].cells[27 - x].className : "x0";
				break;
			}
		}
		flag = true;
		for(var y = 0; y < 28; ++ y)
			flag = dsp.rows[y].cells[1].className == "x0" ? flag : false;
		if(flag) {
			for(var x = 0; x < 28; ++ x)
				for(var y = 0; y < 28; ++ y)
					dsp.rows[y].cells[x].className = dsp.rows[y].cells[1 + x].className;
		}
		MouseDraw.x1 =  -1, MouseDraw.y1 = -1;
		for(var y = 0; y < 28; ++ y) {
			for(var x = 0, code = 0; x < 28; ++ x) {
				code = (code << 1) | (dsp.rows[y].cells[x].className != "x0" ? 1 : 0);
				if(dsp.rows[y].cells[x].className == "x3")
					max = max < x ? x : max;
			}
			if(y && !code)
				break;
			z.push(Number(0x70000000 | code).toString(16).substr(1).toUpperCase());
		}
		z.push("0000000");
/*
01110 :3

*/
		max = ((max + 1) >> 2) + 1;
		for(var i in z)
			z[i] = z[i].substr(0, max);
		document.getElementsByTagName("button")[0].innerText = z.join(" ");
	});
	Display.addEventListener("mouseover", function (evt) {
		evt = evt || window.event;
		var elm = evt.target ? evt.target : evt.srcElement;
		var par = elm.parentNode;
		MouseDraw.x2 = elm.cellIndex, MouseDraw.y2 = par.rowIndex;
		var	idx = MouseDraw.x2 + MouseDraw.y2 * 64;
		if(MouseDraw.x1 == MouseDraw.x2 || MouseDraw.y1 == MouseDraw.y2)
			elm.offsetParent.cells[idx].className = MouseDraw.pen;
	});
	for(y = 0; y < 64; ++ y) {
		row = Display.insertRow(y);
		for(x = 0; x < 64; ++ x) {
			cell = row.insertCell(x);
			cell.innerHTML = "·";
			Matrix.push(0);
			cell.className = "x0";
		}
	}
	document.getElementById("Panel").rows[0].cells[0].appendChild(Display);
	Print("32,32,0 007FFE00 00800100 00A27900 00A28500 00A26100 00A21900 00948500 3F0878FE 40000001 4CC1999D 52A22551 52CA2559 56A22551 4CA1999D 40000001 3FFFFFFE");
	Print("10,10," + (Math.floor(Math.random() * 4) % 4) + " " + Collections.Alikberov);
	Print("29,10," + (Math.floor(Math.random() * 4) % 4) + " " + Collections.Ruslan);
	Print("48,11," + (Math.floor(Math.random() * 4) % 4) + " " + Collections.Internet);
	Print("8,27," + (Math.floor(Math.random() * 4) % 4) + " " + Collections.Monitor);
	Timer();
}

function	Timer() {
	setTimeout(Timer, Speed < 0 ? -Speed : Speed > 0 ? Speed : 125);
	if(Speed > 0)
		DrawASCII(Bug());
	else
	if(Speed < 0)
		Bug_vovel = Bug_isVovel(Bug_x, Bug_y, Bug_z) ? 4 : 0;
	else
		Bug(), Bug(), Bug(), Bug(), Bug(), Bug(), Bug(), DrawASCII(Bug());
}
function	Direction(direction) {
	switch((Bug_w + direction) & 3) {
	case 3:	return {dx: -1, dy: +0};
	case 2:	return {dx: -0, dy: +1};
	case 1:	return {dx: +1, dy: -0};
	default:return {dx: +0, dy: -1};
	}
}
function	Bug_isVovel(x, y, z) {
	var	dsp = document.getElementById("Display");
	var	dir = Direction(z);
	while(dsp.rows[y + dir.dy].cells[x + dir.dx].className == "x3")
		x += dir.dx, y += dir.dy;
	return (dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x3") == (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x3");
}
function	Bug() {
	var	xl, yl, xr, yr, ul, ur, vl, vr, st, ps = false;
	var	dsp = document.getElementById("Display"), dir = Direction(Bug_z);
	var	bit = dsp.rows[Bug_y].cells[Bug_x].className == "x3" ? 1 : 0;
	if(!bit && (st = Stack.pop())) {
		Book.push(Bug_z & 7);
		if(dsp.rows[st.y].cells[st.x].className != "x3")
			return true;
		if(Bug_oct)
			Book.push(8), Bug_oct = false, Bug_s = false;
		dir = Direction(Bug_z = st.z), Bug_y = st.y, Bug_x = st.x;
		bit = dsp.rows[Bug_y].cells[Bug_x].className == "x3" ? 1 : 0;
		if(Bug_vovel && (Bug_x != Bug_px + dir.dx || Bug_y != Bug_py + dir.dy))
			Book.push(8);
		Bug_vovel = Bug_z & 4;
	}
	if(bit) {
		if(MinX > Bug_x)
			MinX = Bug_x;
		if(MinY > Bug_y)
			MinY = Bug_y;
		if(MaxX < Bug_x)
			MaxX = Bug_x;
		if(MaxY < Bug_y)
			MaxY = Bug_y;
		Bug_l = dsp.rows[yl = Bug_y - dir.dx].cells[xl = Bug_x + dir.dy].className == "x3" ? 8 : 0;
		Bug_r = dsp.rows[yr = Bug_y + dir.dx].cells[xr = Bug_x - dir.dy].className == "x3" ? 2 : 0;
		ul = {x: xl, y: yl, z: 0 + ((Bug_z + 3) & 3)}, ur = {x: xr, y: yr, z: 0 + ((Bug_z + 1) & 3)};
		vl = {x: xl, y: yl, z: 4 + ((Bug_z + 3) & 3)}, vr = {x: xr, y: yr, z: 4 + ((Bug_z + 1) & 3)};
		bit = dsp.rows[Bug_y + dir.dy].cells[Bug_x + dir.dx].className == "x3" ? 1 : 0;
		switch(Bug_l | Bug_vovel | Bug_r | bit) {
		case 0x0:	if(Stack.length) Bug_oct = true; else Book.push(Bug_z & 7); break;
		case 0x2:	Stack.push(ur); break;
		case 0x3:	Stack.push(Bug_isVovel(Bug_x, Bug_y, Bug_z + 1) ? vr : ur); break;
		case 0x4:	if(!Stack.length) Book.push(Bug_z & 7); break;
		case 0x6:	if(Bug_isVovel(Bug_x, Bug_y, Bug_z + 1)) ps = true, Stack.push(vr); else Stack.push(ur); break;
		case 0x7:	if(Bug_isVovel(Bug_x, Bug_y, Bug_z + 1)) ps = true, Stack.push(vr); else Stack.unshift(ur); break;
		case 0x8:	Stack.push(ul); break;
		case 0x9:	Stack.push(Bug_isVovel(Bug_x, Bug_y, Bug_z + 3) ? vl : ul); break;
		case 0xC:	if(Bug_isVovel(Bug_x, Bug_y, Bug_z + 3)) ps = true, Stack.push(vl); else Stack.push(ul); break;
		case 0xD:	if(Bug_isVovel(Bug_x, Bug_y, Bug_z + 3)) ps = true, Stack.push(vl); else Stack.unshift(ul); break;
		case 0xE:	ps = true; Stack.push(vl, vr); break;
		}
		if(ps)
			Bug_px = Bug_x, Bug_py = Bug_y;
		dsp.rows[Bug_y].cells[Bug_x].className = Bug_s ? "x4" : Bug_vovel ? "x1" : "x2";
		Bug_x += dir.dx, Bug_y += dir.dy;
		return false;
	}
	if(Stack.length)
		return false;
	if(document.getElementById("Words").length == 0)
		Bug_vovel = 4;
	return true;
}
// Finally bits between: B-P C-S D-T G-K L-R M-N F-V H-X
function Fine() {
	var	dsp = document.getElementById("Display");
	var	dir = Direction(0);
	var	key = 0, bit = 1;
	var	x, y;
	var	i, j, i1 = Bug_w & 1 ? MinY : MinX, j1 = Bug_w & 1 ? MinX : MinY, i2 = Bug_w & 1 ? MaxY : MaxX, j2 = Bug_w & 1 ? MaxX : MaxY;
	Bug_fx = 0;
	for(var j = j2 - j1; j >= 0; -- j) for(var i = i2 - i1; i >= 0; -- i) {
		switch(Bug_w) {
		case 0: x = MaxX - i, y = MaxY - j; break;
		case 1: x = MinX + j, y = MaxY - i; break;
		case 2: x = MinX + i, y = MinY + j; break;
		case 3: x = MaxX - j, y = MinY + i; break;
		}
		if("x0x3x5x6x7".indexOf(dsp.rows[y - 1].cells[x].className) >= 0
		&& "x0x3x5x6x7".indexOf(dsp.rows[y].cells[x - 1].className) >= 0
		&& "x0x3x5x6x7".indexOf(dsp.rows[y + 1].cells[x].className) >= 0
		&& "x0x3x5x6x7".indexOf(dsp.rows[y].cells[x + 1].className) >= 0
		&& "x0x3".indexOf(dsp.rows[y].cells[x].className) >= 0) {
			key |= dsp.rows[y].cells[x].className == "x3" ? bit : 0;
			dsp.rows[y].cells[x].className = key & bit ? "x7" : "x6";
			bit <<= 1; Bug_fx ++;
			if(bit > 0x3FFFFFFF)
				bit = 0;
		} else
		if("x0".indexOf(dsp.rows[y].cells[x].className) >= 0)
			dsp.rows[y].cells[x].className = "x5";
	}
	Bug_sm = (MaxX - MinX + 1) * (MaxY - MinY + 1);
	if(!bit || Bug_fine)
		key = Bug_fine;
	return bit > 1 ? key : -1;
}
function FindBox() {
	var	dsp = document.getElementById("Display");
	Bug_z = 1;
	for(Bug_w = 0; Bug_w < 4; ++ Bug_w) for(Bug_y = 1; Bug_y < 63; ++ Bug_y) for(Bug_x = 1; Bug_x < 63; ++ Bug_x){
		var	dir = Direction(Bug_z), vol = 0;
		var	x = Bug_x, y = Bug_y;
		var	z = (dsp.rows[y].cells[x].className == "x3")
			&& (dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x0")
			&& (dsp.rows[y - dir.dy].cells[x + dir.dx].className == "x0")
			&& (dsp.rows[y + dir.dy].cells[x - dir.dx].className == "x0") 
			? 1 : 0;
		while(z > 0 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x3")
		&& (dsp.rows[y + dir.dy].cells[x + dir.dx].className == "x0"))
			y += dir.dx, x -= dir.dy, z |= 2, ++ vol;
		if(dsp.rows[y + dir.dy].cells[x + dir.dx].className != "x0")
			z = 0;
		while(z > 2 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y - dir.dy].cells[x - dir.dx].className == "x3")
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x0"))
			y -= dir.dy, x -= dir.dx, z |= 4, ++ vol;
		if(dsp.rows[y + dir.dx].cells[x - dir.dy].className != "x0")
			z = 0;
		while(z > 6 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x3")
		&& (dsp.rows[y - dir.dy].cells[x - dir.dx].className == "x0"))
			y -= dir.dx, x += dir.dy, z |= 8, ++ vol;
		if(dsp.rows[y - dir.dy].cells[x - dir.dx].className != "x0")
			z = 0;
		while(z > 14 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y + dir.dy].cells[x + dir.dx].className == "x3")
		&& (dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x0"))
			y += dir.dy, x += dir.dx, z |= 16, ++ vol;
		if(dsp.rows[y - dir.dx].cells[x + dir.dy].className != "x0")
			z = 0;
		if(z == 31 && vol > 10) {
			if((dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x0")
			&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x0")) {
				Bug_w = (Bug_w + 1) & 3;
				return true;
			}
		}
	}
	Bug_y = 1; Bug_x = 1; Bug_w = 0;
	return false;
}
function FindBox_neo() {
	var	dsp = document.getElementById("Display");
	Bug_z = 1;
	for(Bug_w = 0; Bug_w < 4; ++ Bug_w) for(Bug_y = 1; Bug_y < 63; ++ Bug_y) for(Bug_x = 1; Bug_x < 63; ++ Bug_x){
		var	dir = Direction(Bug_z), vol = 0;
		var	x = Bug_x, y = Bug_y;
		var	z = (dsp.rows[y].cells[x].className == "x3")
			&& (dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x0")
			&& (dsp.rows[y - dir.dy].cells[x + dir.dx].className == "x0")
			&& (dsp.rows[y + dir.dy].cells[x - dir.dx].className == "x0") 
			? 1 : 0;
		while(z > 0 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x3")
		&& (dsp.rows[y + dir.dy].cells[x + dir.dx].className == "x0"))
			y += dir.dx, x -= dir.dy, z |= 2, ++ vol;
		if(dsp.rows[y + dir.dy].cells[x + dir.dx].className != "x0")
			z = 0;
		while(z > 2 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y - dir.dy].cells[x - dir.dx].className == "x3")
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x0"))
			y -= dir.dy, x -= dir.dx, z |= 4, ++ vol;
		if(dsp.rows[y + dir.dx].cells[x - dir.dy].className != "x0")
			z = 0;
		while(z > 6 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x3")
		&& (dsp.rows[y + dir.dy].cells[x + dir.dx].className == "x0"))
			y += dir.dx, x -= dir.dy, z |= 8, ++ vol;
		if(dsp.rows[y + dir.dy].cells[x + dir.dx].className != "x0")
			z = 0;
		while(z > 14 && x > 0 && x < 63 && y > 0 && y < 63
		&& (dsp.rows[y - dir.dy].cells[x - dir.dx].className == "x3")
		&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x0"))
			y -= dir.dy, x -= dir.dx, z |= 16, ++ vol;
		if(dsp.rows[y + dir.dx].cells[x - dir.dy].className != "x0")
			z = 0;
		if(z == 31 && vol > 6) {
			if((dsp.rows[y - dir.dx].cells[x + dir.dy].className == "x0")
			&& (dsp.rows[y + dir.dx].cells[x - dir.dy].className == "x0")) {
				Bug_w = (Bug_w + 1) & 3;
				return true;
			}
		}
	}
	Bug_y = 1; Bug_x = 1; Bug_w = 0;
	return false;
}
function Print(txt) {
	var	dsp = document.getElementById("Display");
	var	msg = document.getElementById("Message");
	if(txt == " ") {
	} else
	if(!txt) {
		msg.innerText = "";
		for(var y = 0; y < 64; ++ y)
			for(var x = 0; x < 64; ++ x)
				dsp.rows[y].cells[x].className = "x0";
		return;
	}
	var cd = txt.split(' '), ox = 0, oy = 0, oz = 0;
	var	Halt = false, Locate = false;
	if(cd[0].indexOf(",") > 0) {
		var	xy = cd.shift().split(",");
		ox = +xy[0], oy = +xy[1];
		if(xy.length > 2)
			oz = +xy[2];
		if(oz > 3)
			Halt = true;
		Locate = true;
	}
	Bug_w = 0;
	var	dir = Direction(oz);
	var	dx = Locate ? (cd[cd.length >> 1].length * 4) >> 1 : 0;
	var	dy = Locate ? cd.length >> 1 : 0;
//	ox = oy * dir.dx - ox * dir.dy;
//	oy = ox * dir.dx + oy * dir.dy;
	for(var y = 0; y < cd.length; ++ y) {
		var	d = cd[y].length, c = parseInt(cd[y], 16);
		var	x = 4 * d;
		while(x --) {
			dsp.rows[oy - (y - dy) * dir.dy + (x - dx) * dir.dx].cells[ox - (x - dx) * dir.dy - (y - dy) * dir.dx].className = c & 1 ? "x3" : "x0";
			c >>= 1;
		}
	}
	if(Halt)
		return;
	if(!FindBox())
		FindBox_neo();
	Bug_vovel = 0;
	Notes = [], Book = [], Stack = [];
	Bug_oct = false, Bug_s = true, Bug_fine = 0, Bug_fx = 0, Bug_sm = 0;;
	MinX = 63, MinY = 63, MaxX = 0, MaxY = 0;
	document.getElementById("Words").options.length = 0;
	document.getElementById("Words").selectedIndex = 0;
}
/*
+0 -1
+1 +0
+0 +1
-1 +0
*/
</script></head>
<body onload='main()'>
<span id='Message' style='font-size: 10px'></span> <select id='Words' select=4></select> <button onclick='Print(this.innerText)' style='font-size: 8px'>0 4</button> <br>
<div></div><br>
<table id='Panel'><tr><td style='vertical-align: top'>
</td><td style='vertical-align: top'><pre id='Pseudo'></pre>
<table><tr><td style='vertical-align: bottom'>
<button onclick='if(Speed < 0) Print(""); else Bug_vovel = 0, Bug_oct = 0, Notes = [], Book = [], Stack = [], MinX = 0, MinY = 0, MaxX = 0, MaxY = 0' title='Reset state/Clear screen'>&#10227;</button>
<button onclick='this.innerHTML = (Draw_oem = !Draw_oem) ? "&#11820;" : "&#9712;"' title='OEM-866 1x2/UNICODE 2x2'>&#11820;</button>
<button onclick='Print(" ")' title='Find next'>NEXT</button><br>
<button onclick='Speed = 1000' title='x1'>&#9657;</button
><button onclick='Speed = 500' title='x2'>&#9656;</button
><button onclick='Speed = 250' title='x4'>&#9193;</button
><button onclick='Speed = 125' title='x8'>&#9654;</button>
<button onclick='this.innerHTML = (Speed = -Speed) < 0 ? "&#9655;" : "&#65793;"; Bug_oct = 0;' title='Start/Pause'>&#9199;</button>
<button onclick='Speed = 0' title='x16'>&#10704;</button>
</td></tr></table>
<table id='Vectors'>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
<pre id='Log'></pre>
</td>
</tr>
</td></tr>
<tr><td>
<table id='Designs'>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</td></tr></table>
<hr />
<p style='text-align:center'>Visit my
<a href='http://groups.google.com/d/forum/logotron/'>Group</a> or
<a href='http://www.gamedev.ru/pages/alikberov/forum/?id=193255'>Forum</a><br>
<a href='http://softrash.googlecode.com/'>Project</a> by Alikberov ©2014.12.13-2014.12.20</p>
</body>
